package com.gs.gaosheng.controller;

import com.gs.common.annotation.Log;
import com.gs.common.core.controller.BaseController;
import com.gs.common.core.domain.AjaxResult;
import com.gs.common.core.page.TableDataInfo;
import com.gs.common.enums.BusinessType;
import com.gs.common.utils.poi.ExcelUtil;
import com.gs.gaosheng.domain.GsOrder;
import com.gs.gaosheng.service.GsOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单Controller
 *
 * @author yy
 * @date 2023-08-03
 */
@RestController
@RequestMapping("/gaosheng/order")
public class GsOrderController extends BaseController
{
    @Autowired
    private GsOrderService gsOrderService;

    /**
     * 查询订单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(GsOrder gsOrder)
    {
        startPage();
        List<GsOrder> list = gsOrderService.selectGsOrderList(gsOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(GsOrder gsOrder)
    {
        List<GsOrder> list = gsOrderService.selectGsOrderList(gsOrder);
        ExcelUtil<GsOrder> util = new ExcelUtil<GsOrder>(GsOrder.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 获取订单详细信息
     */
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return AjaxResult.success(gsOrderService.selectGsOrderById(orderId));
    }

    /**
     * 新增订单
     */
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GsOrder gsOrder)
    {
        return toAjax(gsOrderService.insertGsOrder(gsOrder));
    }

    /**
     * 修改订单
     */
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GsOrder gsOrder)
    {
        return toAjax(gsOrderService.updateGsOrder(gsOrder));
    }

    /**
     * 删除订单
     */
    @Log(title = "订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(gsOrderService.deleteGsOrderByIds(orderIds));
    }
}
